public class test4 {
    //力扣 1047.删除字符串中的相邻重复项
    public String removeDuplicates(String s) {
        StringBuffer ret = new StringBuffer();
        char[] sarr = s.toCharArray();
        for(char ch:sarr){
            if(ret.length()>0 && ch==ret.charAt(ret.length()-1)){
                //出栈
                ret.deleteCharAt(ret.length()-1);

            }else{
                //进栈
                ret.append(ch);
            }
        }
        return ret.toString();
    }
}
